<style lang="less">

</style>
<template>
  <div class="tops">
      <div>
        1212321333

      </div>
    </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      createUser: 0,
      visit: 0,
      collection: 0,
      transfer: 0,
      tableData: [],
      orders: 0,
      master:{
        Threemen:0,
        Threeorders:0
      },
      total: 0,
      size: 10,
      index: 1,

      dialogVisible: false,
      dialogVisibles: false,
      nickname: '',
      totalUser: 0,
      sizeUser: 5,
      indexUser: 1,
      userList: [],
      csType: 0,
      userInfo: {},
      customMon: null
    };
  },
  computed: {},
  mounted() {
    this.$store.commit("cactive", "home");
    this.userSum();
    this.getData();
  },
  methods: {
    async CSmoney(){
      if(this.customMon!=null&&this.customMon>0){
        this.customMon = this.customMon.toFixed(2);
        if(this.csType==0){
          //充值
          try{
            let parse = {unionid:this.userInfo.unionid,
                      nickname:this.userInfo.nickname,
                      headimgurl:this.userInfo.headimgurl,
                      money:this.customMon };
            let retur = await this.$http.post("/recharge/adminRecharge", parse);
            if(retur.data==1){
              this.$message({
                type: 'success',
                message: '充值成功！'
              });
              this.dialogVisibles = false;
              this.userSum();
            }else{
              this.$message({
                message: '充值失败！'
              });
              this.dialogVisibles = false;
            }
          } catch (error) {
            console.log(error);
            this.$message({
              message: '充值失败！'
            });
            this.dialogVisibles = false;
          }
        }else{
          //提现

          try{
            let parse = {unionid:this.userInfo.unionid,
                      nickname:this.userInfo.nickname,
                      headimgurl:this.userInfo.headimgurl,
                      money:this.customMon };
            let retur = await this.$http.post("/cash/adminCash", parse);
            if(retur.data==1){
              this.$message({
                type: 'success',
                message: '提现成功！'
              });
              this.dialogVisibles = false;
              this.userSum();
            }else{
              this.$message({
                message: '提现失败！'
              });
              this.dialogVisibles = false;
            }
          } catch (error) {
            console.log(error);
            this.$message({
              message: '提现失败！'
            });
            this.dialogVisibles = false;
          }

        }
      }else{
        this.$message({
          message: '金额必须大于0！'
        });
      }
    },
    cs(m){
      this.userInfo = m;
      console.log(this.userInfo)
      this.dialogVisible = false;
      this.dialogVisibles = true;
    },
    csSelect(n){
      this.csType = n;
      this.dialogVisible = true;
      this.indexUser = 1;
      this.customMon = null;
      this.getUserData();
    },
    suosou(){
      this.indexUser = 1;
      this.getUserData();
    },
    userChange: function(page){ 
      this.indexUser = page
      this.getUserData();
    },
    async getUserData(){
      let nickname = this.nickname || "";
      let params = { nickname, page: this.indexUser, size: this.sizeUser };
      try {
        let result = await this.$http.get("/user/getUserSelect", { params });
        this.userList = result.data.data;
        this.totalUser = result.data.total;
      } catch (error) {
        console.log(error);
      }
    },


    async userSum() {
      let orders = await this.$http.get("/order/orderNum");
      this.orders = orders.data;
      let userSum = await this.$http.get("/user/userSum");
      this.visit = userSum.data;
      let userDaySum = await this.$http.get("/user/userDaySum");
      this.createUser = userDaySum.data;
      let master = await this.$http.get("/super/getmaster");
      this.master = master.data;
      let cashDaySum = await this.$http.get("/cash/cashDaySum");
      let rechargeDaySum = await this.$http.get("/recharge/rechargeDaySum");
      this.transfer = cashDaySum.data;
      this.collection = rechargeDaySum.data;
    },
    handleCurrentChange: function(page) {
      this.index = page;
      this.getData();
    },
    getMoney(num) {
      if(num==0){
        return 0
      }else{
        if(num==null){
          return;
        }else{
          return num.toFixed(2);
        }
      }

    },
    getDay(num) {
      let t = new Date(num);
      return (
        t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate()
      );
    },
    async getData() {
      let params = { size: this.size, index: this.index  };
      try {
        let result = await this.$http.get("/super/pageTotal", { params });
        this.tableData = result.data.data;
        this.total = result.data.total;
      } catch (error) {
        console.log(error);
      }
    }
  }
};
</script>
